import AdManager from "./AdManager";
import AudioManager from "./AudioManager";
import BasePageCtrl, { AnimType } from "./BasePageCtrl";
import MomGivesMoneyPage from "./MomGivesMoneyPage";
import NativeUtils from "./NativeUtils";
import PeripheralSystemDataMgr from "./PeripheralSystemDataMgr";
import PeripheralSystemMgr, { TravelEvent } from "./PeripheralSystemMgr";
import SdkHelper from "./SdkHelper";
import UiManager from "./UiManage";

const { ccclass, property } = cc._decorator;

@ccclass
export default class MomGivesMoneyPageCtrl extends BasePageCtrl {
    @property(cc.Node)
    ui = null;

    onLoad() {
        this.onUILoad();
        this._animType = AnimType.BOTTOM_TO_TOP;
        this._touchControl = false;
        this._hasPeneLock = true;
        this._hasBlack = true;
        this._hasTouchLock = false;
        this._hasBlackTouch = false;
        this._showWinSize = true;
        this.addButtonListen();
    }

    start() { }

    _init() {
        AudioManager.getInstance().playMusic("mom_give_mom");
        this.playCloseBtnAction();
        this.playRedPaperAction();
    }

    playRedPaperAction() {
        const e = cc.tween()
            .to(0.1, { angle: -10 })
            .to(0.1, { angle: 10 })
            .to(0.1, { angle: 10 })
            .to(0.1, { angle: -10 });
        const t = cc.tween().repeatForever(e);
        cc.tween(this.ui.redPaper).then(t).start();
    }

    playCloseBtnAction() {
        const e = this;
        this.ui.btn_close.active = false;
        this.scheduleOnce(() => {
            e.ui.btn_close.active = true;
        }, 2);
    }

    onUILoad() {
        this.ui = this.node.addComponent(MomGivesMoneyPage);
    }

    addButtonListen() {
        UiManager.addButtonListen(this.ui.btn_video, this.clickVideo, this);
        UiManager.addButtonListen(this.ui.btn_close, this.clickClose, this);
    }

    clickVideo() {
        const e = this;
        PeripheralSystemDataMgr.reportEncourageVideo();
        SdkHelper.showForceToast("看完广告就能获得大量红包");
        NativeUtils.showVideoAd(7, () => {
            PeripheralSystemMgr.getVideoReward(TravelEvent.MOM_GIVE_MOENY);
            e.hide();
        });
    }

    clickClose() {
        this.hide();
        PeripheralSystemDataMgr.checkNextOutSideGuide();
        PeripheralSystemDataMgr.checkShowGameStartPage();
    }


    static prefabUrl = "MomGivesMoneyPage";
    static className = "MomGivesMoneyPageCtrl";

}
